<admintpl file="header" />
<style>
    .add{
       margin-top: 40px;
       overflow: hidden;
    }
    .add ul{
       overflow: hidden;
    }
    .add ul li{
        list-style: none;
        float: left;
        margin-right: 8px;
    }
    .add button{
        height: 36px;
        width: 84px;
        background: darkseagreen;
    }
    table button{
        background: red;
    }
    table td input{
        width: 120px;
    }
    button{
        color: white;
    }
    .attr{
        width: 100%;
        height: 40px;
        margin: 12px 0px;
        overflow: hidden;
    }
    .attr ul{
        padding: 0px;
        overflow: hidden;
    }
    .attr ul li{
        list-style: none;
        float: left;
        height: 40px;
        line-height: 40px;
        padding: 0px 12px;
        margin-right: 12px;
        background: dodgerblue;
        cursor: pointer;
        border-radius: 6px;
        color: white;
    }
</style>
<script type="text/javascript" src="__PUBLIC__/uploadify/jquery.uploadify.min.js"></script>
<link rel="stylesheet" href="__PUBLIC__/uploadify/uploadify.css">
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:U('Product/index')}">商品列表</a></li>
        <li class="active" ><a href="{:U('Parameter/index',array('pro_id'=>$_GET['pro_id']))}"> 商品规格 </a></li>
    </ul>

    <div class="add">
        <ul>
            <li>
                规格名
                <input type="text" value="" id="key" placeholder="请输入规格名">
            </li>
            <li>
                规格值
                <input type="text" value="" id="value" placeholder="多个值用“|”隔开">
            </li>
            <li>
                <button id="add_attr">添加</button>
            </li>
        </ul>
    </div>
    <div class="attr">
        <ul>
            <if condition ="$data['para_name']">
                <foreach name="data['para_name']" item="i">
                    <li class="delete"> {$i} </li>
                </foreach>
            </if>
        </ul>
    </div>
    <form action="{:U('Parameter/update')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
        <fieldset style="overflow: hidden;">

                <table class="table">
                     <tr style="font-weight: 700">
                        <td style="min-width: 120px;">ID</td>
                        <td style="min-width: 120px;">规格名</td>
                        <td style="min-width: 120px;">规格值</td>
                        <td>库存</td>
                        <td>价格</td>
                        <td>促销价格</td>
                        <!--<td>操作</td>-->
                     </tr>
                    <foreach name="list" item = "vo">
                     <tr>
                             <td>
                                 {$vo['id']}
                                 <input type="hidden" name="ids[]" value="{$vo['id']}">
                             </td>
                             <td>{$vo['attr_title']}</td>
                             <td>{$vo['attr_value']}</td>
                             <td><input type="text" name="stock[]" value="{$vo['stock']}"></td>
                             <td><input type="text" name="price[]" value="{$vo['price']}"></td>
                             <td><input type="text" name="price_plus[]" value="{$vo['price_plus']}"></td>
                             <!--<td><button>删除</button></td>-->
                     </tr>
                    </foreach>
                </table>

        </fieldset>
        <input type="hidden" value="{$_GET['pro_id']}" name="pro_id">
        <div class="form-actions">
            <button class="btn btn-primary js-ajax-submit" type="submit">{:L("SAVE")}</button>
            <a class="btn" href="{:U('Product/index')}">返回</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script>
    $(function(){
        $(".delete").click(function(){
            var pro_id = "{$_GET['pro_id']}";
            var attr = $(this).html();
            if(confirm('确定删除这个规格吗?')){
                $.post("{:U('Parameter/delete')}",{
                    pro_id:pro_id,
                    attr:attr
                },function(data){
                    var data = JSON.parse(data);
                    if(data.code == 1){
                        window.location.reload();
                    }
                })
            }
        })
    })
</script>
<script>
    $(function(){
        $("#add_attr").click(function(){
            var id = "{$_GET['pro_id']}";
            var key = $("#key").val();
            var val = $("#value").val();
            if(!key){
               alert("请填写规格名")
            }else if(!val){
                alert("请填写规格值")
            }
            $.post("{:U('Parameter/add')}",{
                pro_id:id,
                key:key,
                val:val
            },function(data){
              var data = JSON.parse(data);
              if(data.code == 1){
                  window.location.reload();
              }
            })
        })
    })
</script>
</body>
</html>